from apps.system.models import SystemSetting
import oss2
from tuntun.settings import ALIYUN_OSS

def upload_http_file():
    token = SystemSetting.get_aliyun_oss_sts_token()
    auth = oss2.StsAuth(token['access_key_id'], token['access_key_secret'], token['security_token'])
    bucket = oss2.Bucket(auth, ALIYUN_OSS['oss_endpoint_without_bucket'], ALIYUN_OSS['bucket'])

    result = bucket.put_object("s")

    #
    #
    # # 上传一段字符串。Object名是motto.txt，内容是一段名言。
    # bucket.put_object('motto.txt', 'Never give up. - Jack Ma')
    #
    #
    # # 下载到本地文件
    # bucket.get_object_to_file('motto.txt', '本地座右铭.txt')
    #
    #
    # # 删除名为motto.txt的Object
    # bucket.delete_object('motto.txt')
    #
    #
    # # 清除本地文件
    # os.remove(u'本地座右铭.txt')
